package com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Statistics.HomeWorkRank.Adapter;

import android.app.Activity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.tnot.R;
import com.example.tnot.Teacher.CoursePart.CourseInternal.CourseDetailHome.Statistics.HomeWorkRank.ItemBean.HomeWorkRank;

import java.util.List;

public class homeworkRankAdapter extends RecyclerView.Adapter<homeworkRankAdapter.ViewHolder> {
    private List<HomeWorkRank> mData;
    private boolean showFinishData = true;
    public homeworkRankAdapter(List<HomeWorkRank> data) {
        mData = data;
    }

    @NonNull
    @Override
    public homeworkRankAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(parent.getContext(), R.layout.item_rv_homework_rank, null);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull homeworkRankAdapter.ViewHolder holder, int position) {
            HomeWorkRank item = mData.get(position);
            holder.iv_icon.setImageResource(mData.get(position).getIcon());
            holder.tv_class.setText(mData.get(position).getClassName());
            holder.tv_name.setText(mData.get(position).getName());
            holder.tv_finish.setText(mData.get(position).getFinishRate());
            holder.tv_accuracy.setText(mData.get(position).getAccuracyRate());
        // 根据标志位决定显示哪种数据
            if (showFinishData) {
                holder.tv_finish.setVisibility(View.VISIBLE);
                holder.tv_accuracy.setVisibility(View.GONE);
                holder.tv_finish.setText(item.getFinishRate());
            } else {
                holder.tv_finish.setVisibility(View.GONE);
                holder.tv_accuracy.setVisibility(View.VISIBLE);
                holder.tv_accuracy.setText(item.getAccuracyRate());
            }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder{
        ImageView iv_icon;
        TextView tv_class,tv_name,tv_finish,tv_accuracy;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            iv_icon = itemView.findViewById(R.id.iv_icon);
            tv_class = itemView.findViewById(R.id.tv_class);
            tv_name = itemView.findViewById(R.id.tv_name);
            tv_finish = itemView.findViewById(R.id.tv_finish);
        }
    }
    public void updateDataType(boolean showFinish) {
        this.showFinishData = showFinish;
        notifyDataSetChanged(); // 刷新数据
    }

}
